/*******************************************************************************
 * Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Eurotech - initial API and implementation
 *
 *******************************************************************************/
package org.eclipse.kapua.service.account.internal;

import org.eclipse.kapua.KapuaException;

/**
 * The KapuaException class is the superclass of exceptions in Kapua project.<br>
 * It extends the JDK Exception class by requesting its invokers to provide an error code when building its instances.<br>
 * The code is one value of KapuaErrorCode; the code is used to document the possible error conditions generated by the platform as well as to identify the localized exception messages to be
 * reported.<br>
 * Exceptions messages are stored in the KapuaExceptionMessagesBundle Properties Bundle and they are keyed on the exception code.
 * 
 * @since 1.0
 * 
 */
public class KapuaAccountException extends KapuaException 
{
	private static final long serialVersionUID = 6422745329878392484L;

	private static final String KAPUA_ERROR_MESSAGES  = "kapua-account-service-error-messages";

	/**
	 * Builds a new KapuaException instance based on the supplied KapuaErrorCode.
	 * 
	 * @param code
	 */
	public KapuaAccountException(KapuaAccountErrorCodes code) {
		super(code);
	}

	/**
	 * Builds a new KapuaException instance based on the supplied KapuaErrorCode 
	 * and optional arguments for the associated exception message.
	 * 
	 * @param code
	 * @param arguments
	 */
	public KapuaAccountException(KapuaAccountErrorCodes code, Object... arguments) {
		super(code, arguments);
	}

	/**
     * Builds a new KapuaAccountException instance based on the supplied KapuaAccountErrorCode,
     * an Throwable cause, and optional arguments for the associated exception message.
     * 
     * @param code
     * @param cause
     * @param arguments
     */
	public KapuaAccountException(KapuaAccountErrorCodes code, Throwable cause, Object... arguments) {
		super(code, cause, arguments);
	}

	/**
	 * Factory method to build an KapuaAccountException with the KapuaAccountErrorCode.INTERNAL_ERROR, 
	 * and optional arguments for the associated exception message.
	 * 
	 * @param message
	 * @return
	 */
	public static KapuaAccountException internalError(String message) {
		return new KapuaAccountException(KapuaAccountErrorCodes.INTERNAL_ERROR, null, message);
	}

	@Override
	protected String getKapuaErrorMessagesBundle() {
		return KAPUA_ERROR_MESSAGES; 
	}
}
